﻿@{
    ViewData["Title"] = "修改密码";
}

<h5>@ViewData["Title"]</h5>

<table class="table">
    <tr>
        <td>输入旧密码</td>
        <td><input id="TBPassword" type="password" class="form-control" maxlength="16" /></td>
        <td><small id="SPassword" class="text-warning"></small></td>
    </tr>
    <tr>
        <td>输入新密码</td>
        <td><input id="TBPassword1" type="password" class="form-control" maxlength="16" /></td>
        <td><small id="SPassword1" class="text-warning"></small></td>
    </tr>
    <tr>
        <td>重输新密码</td>
        <td><input id="TBPassword2" type="password" class="form-control" maxlength="16" /></td>
        <td><small id="SPassword2" class="text-warning"></small></td>
    </tr>
    <tr><td colspan="3"><button class="btn btn-primary" onclick="Save()">提交</button></td></tr>
</table>

@section Scripts
{
    <script>

        $(function () {

            $("#TBPassword").change(function () {
                if ($("#TBPassword").val() == "") {
                    $("#SPassword").html("旧不能为空");
                }
                CallAjax("@Url.Action("CheckPassWord")", {
                   passWord: $("#TBPassword").val(),
                   userName:"@User.Identity.Name"

                }, function (ret) {
                        if (ret.message == 1)
                       $("#SPassword").html("旧密码错误");
                        else
                            $("#SPassword").html("");

                });
            });


            $("#TBPassword1").change(function () {
                if ($("#TBPassword1").val().length<6) {
                    $("#SPassword1").html("密码长度不能小于6");
                }
                else
                    $("#SPassword1").html("");
            });

            $("#TBPassword2").change(function () {
                if ($("#TBPassword1").val()!=$("#TBPassword2").val()) {
                    $("#SPassword1").html("两次输入密码不一样");
                }
                else
                    $("#SPassword2").html("");
            });

        });


        function Save() {

            if ($("#TBPassword").val() == "") {
                ShowMessage("旧密码不能为空");
                return;
            }
            if ($("#TBPassword1").val().length < 6) {
                ShowMessage("密码长度不能小于6");
                return;
            }
            if ($("#TBPassword1").val() != $("#TBPassword2").val()) {
                ShowMessage("两次输入密码不一样");
                return;
            }

            CallAjax("@Url.Action("ChangePassword")", {
                password: $("#TBPassword1").val(),
                   userName:"@User.Identity.Name"
            }, function (ret) {
                    if (ret.message == 0)
                    {
                        $('.toast').toast('show');
                        window.location.href = "@Url.Action("Login","Account")";
                    }
                    else
                    ShowMessage(ret.message);
            });

        }

    </script>

}